package com.beijiteshop.shop.ui.detail.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.beijiteshop.libcommon.ext.databinding.inflateBinding
import com.beijiteshop.shop.R
import com.beijiteshop.shop.data.DataServer
import com.beijiteshop.shop.databinding.DialogColorSelectionBinding
import com.beijiteshop.shop.ui.detail.TextFlexBoxRVHelper
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.ToastUtils
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

/**
 * @Author LiaoZhongKai
 * @Date 2021/3/5 15:49
 * @Description 商品详情颜色选择框
 */
class ColorSelectionDialog private constructor(): BottomSheetDialogFragment() {

    companion object{

        fun show(fragmentManager: FragmentManager){
            val dialog = ColorSelectionDialog()
            dialog.show(fragmentManager,"")
        }
    }

    private lateinit var mBinding: DialogColorSelectionBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(DialogFragment.STYLE_NORMAL, R.style.TransBgBottomSheet)
    }

    override fun onStart() {
        super.onStart()
        //设置默认高度
        val bottomSheet = dialog?.findViewById<FrameLayout>(R.id.design_bottom_sheet)
        bottomSheet?.let {
            it.layoutParams.height = ScreenUtils.getScreenHeight() / 2
        }
    }


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = inflateBinding(inflater)
        return mBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initRV()
    }

    private fun initRV(){
        mBinding.colorSelectionRv.itemAnimator = null
        TextFlexBoxRVHelper.bind(requireContext(),
            mBinding.colorSelectionRv,DataServer.getProductColors(),R.drawable.bg_product_color_selector,R.color.text_dark){index, data ->
            ToastUtils.showShort(data)
        }
    }
}